package com.algorithm.collection.spliterator;


/**
 *计算字符串的数字之和的实体类
 */
public class NumCounter {

    /**
     * 当前数字
     */
    private int num;

    /**

     * 数字之和
     */
    private int sum;

    /**
     * 是否是个完整的数字
     */
    private boolean isWholeNum;

    public NumCounter(int num, int sum, boolean isWholeNum) {
        this.num = num;
        this.sum = sum;
        this.isWholeNum = isWholeNum;
    }

    public NumCounter accumulate(Character c){
        //判断当前字符是否是数字
        if(Character.isDigit(c)){
           if(isWholeNum){
               return new NumCounter(Integer.parseInt(c.toString()),sum,Boolean.FALSE);
           }else{
               return new NumCounter(Integer.parseInt(num+c.toString()),sum,Boolean.FALSE);
           }
        }else{
            return new NumCounter(0,sum+num,true);
        }
    }

    public NumCounter combine(NumCounter numCounter){
        return new NumCounter(0, this.getSum() + numCounter.getSum(), numCounter.isWholeNum);
    }


    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public int getSum() {
        return sum;
    }

    public void setSum(int sum) {
        this.sum = sum;
    }

    public boolean isWholeNum() {
        return isWholeNum;
    }

    public void setWholeNum(boolean wholeNum) {
        isWholeNum = wholeNum;
    }






}
